package lhc.alg.top100;

/**
 * description: https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/
 * 买卖股票的最佳时机  1
 * author: hongchen.liao
 * date:  2022/9/25
 */
public class _121_ {

    class Solution {
        public int maxProfit(int[] prices) {
            int n = prices.length;
            int dp_i_0 = 0, dp_i_1 = Integer.MIN_VALUE;
            for(int i = 0; i < n; i++){
                dp_i_0 = Math.max(dp_i_0, dp_i_1 + prices[i]);
                dp_i_1 = Math.max(dp_i_1, -prices[i]);
            }
            return dp_i_0;
        }
    }

}
